package com.project.collectAPI.entity.MeiTuanBatchDelete;


import com.project.collectAPI.comm.SpiderTools;
import com.project.collectAPI.entity.MeiTuan.SystemParam;
import lombok.Data;
import org.apache.http.client.config.RequestConfig;

import java.util.HashMap;
import java.util.Map;

@Data
/*批量删除商品类目和商品API*/
public class MeiTuanBatchDelete {

    private String reqAPI="https://waimaiopen.meituan.com/api/v1/retailCat/batchdelete/catandretail";

    private Boolean isDeleteAll=false;

    //统一的时间戳
    private Long timestamp;

    //签名
    private String signValue;

    //APP方门店id，即商家中台系统里门店的编码。如商家在操作绑定门店至开放平台应用中时，未绑定三方门店id信息，则默认APP方门店id与美团门店id相同。
    private String app_poi_code;

    //一级分类id
    private String category_codes;

    //一级分类名称(根据该名称删除旗下所有分类及其商品)
    private String category_names;


    /*获取美团类目接口签名*/
    public String getSign() throws Exception {
        SystemParam systemParam=new SystemParam();
        Map<String,Object> map=new HashMap<>();
        map.put("timestamp",timestamp);  //timestamp尽量统一用一次
        map.put("app_id",systemParam.getAppId());
        map.put("app_poi_code",app_poi_code);
        if(!isDeleteAll) {
            map.put("category_names", category_names);
        }
        return systemParam.getSign(map,reqAPI); //获取签名
    }

    public String StartDelete() throws Exception {

        SystemParam systemParam=new SystemParam();
        //String reqUrl=reqAPI+"?app_id="+systemParam.getAppId()+"&app_poi_code="+app_poi_code+"&timestamp="+timestamp+"&sig="+signValue;

        Map<String, String> applicationParamsMap=new HashMap<>();
        applicationParamsMap.put("app_id",systemParam.getAppId());
        applicationParamsMap.put("app_poi_code",app_poi_code);
        applicationParamsMap.put("timestamp",String.valueOf(timestamp));
        if(!isDeleteAll) {
            applicationParamsMap.put("category_names",category_names);
        }
        applicationParamsMap.put("sig",signValue);
        RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
        // ConnectTimeout:连接超时.连接建立时间，三次握手完成时间.
        requestConfigBuilder.setConnectTimeout( 30000* 1000);
        String res= SpiderTools.requestOfPost(reqAPI, applicationParamsMap,requestConfigBuilder);
        System.out.println("删除分类菜单服务器返回结果=========>:");
        System.out.println(res);
        return res;
    }

} //class End
